﻿@model List<ReportCountModel>
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "报文量统计";
}
<link href="/Content/assets/plugins/bootstrap-datepicker/css/datepicker.css" rel="stylesheet" />
<link href="/Content/assets/plugins/bootstrap-datepicker/css/datepicker3.css" rel="stylesheet" />
<div id="content" class="content">
    <!-- begin breadcrumb -->
    <ol class="breadcrumb pull-right">
        <li><a href="@Url.Action("ReportList","Home")">报文列表</a></li>
        <li class="active"><a href="javascript:;">报文量统计</a></li>
    </ol>
    <!-- end breadcrumb -->
    <!-- begin page-header -->
    <!-- end page-header -->
    <!-- begin row -->
    <div class="row">
        <!-- begin col-12 -->
        <div class="col-md-12">
            <!-- begin panel -->
            <div class="panel panel-inverse">
                <div class="panel-body">
                    <div class="table-responsive">
                        
                        <table id="data-table" class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>MMSI</th>
                                <th>船名</th>
                                <th>AGENCY</th>
                                <th>ANCHORAGE</th>
                                <th>ARRIVAL</th>
                                <th>BERTHING</th>
                                <th>DAILY</th>
                                <th>DEPARTURE</th>
                                <th>POSITION</th>
                                <th>ROUTE</th>
                                <th>SHIFTING</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach (var data in Model)
                            {
                                int agency = data.ReportList.Where(m => m.Type == "AGENCY").Count();
                                int anchorage = data.ReportList.Where(m => m.Type == "ANCHORAGE").Count();
                                int arrival = data.ReportList.Where(m => m.Type == "ARRIVAL").Count();
                                int berthing = data.ReportList.Where(m => m.Type == "BERTHING").Count();
                                int daily = data.ReportList.Where(m => m.Type == "DAILY").Count();
                                int departure = data.ReportList.Where(m => m.Type == "DEPARTURE").Count();
                                int position = data.ReportList.Where(m => m.Type == "POSITION").Count();
                                int routeplan = data.ReportList.Where(m => m.Type == "ROUTE").Count();
                                int shifting =data.ReportList.Where(m => m.Type == "SHIFTING").Count();
                                bool flag = false;
                                if(agency==0&&anchorage==0&&arrival==0&berthing==0&daily==0&&departure==0&&position==0&&routeplan==0&&shifting==0)
                                {
                                    flag = true;
                                }

                                <tr class="odd" @(flag?"style=color:red;":"") >
                                    <td>@data.MMSI</td>
                                    <td>@data.ShipName</td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','AGENCY')"> @agency</a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','ANCHORAGE')"> @anchorage </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','ARRIVAL')">@arrival </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','BERTHING')"> @berthing </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','DAILY')">@daily </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','DEPARTURE')"> @departure </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','POSITION')"> @position </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','ROUTE')"> @routeplan </a></td>
                                    <td><a @(flag?"style=color:red;":"") href="javascript:; " onclick="ShowList('@data.MMSI','SHIFTING')"> @shifting </a></td>
                                </tr>
                            }
                            </tbody>
                        </table>
                        <div class="dataTables_length">
                            <div class="input-group input-daterange col-md-4" style="padding-left: 1%;" data-date-format="yyyy-mm-dd">
                                <input type="text" class="form-control" name="start" id="start" placeholder="开始时间">
                                <span class="input-group-addon">到</span>
                                <input type="text" class="form-control" name="end" id="end" placeholder="结束时间">
                                <span class="input-group-addon" id="search" style="cursor: pointer; ">查询</span>
                            </div>
                        </div>
                       
                    </div>
                </div>
            </div>
            <!-- end panel -->
        </div>
        <!-- end col-12 -->
    </div>
    <!-- end row -->
</div>

@section footer {
    <script src="/Content/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script src="/Content/assets/plugins/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script>
    <script>

        $(document)
            .ready(function() {
                $('.input-daterange')
                    .datepicker({
                        language: 'zh-CN',
                        autoclose: true,
                        todayHighlight: true
                    });
                App.init();
                $("#data-table")
                    .DataTable({
                        "paging": false
                    });


                $("#search")
                    .click(function() {
                        var start = $("#start").val();
                        var end = $("#end").val();
                        window.location.href = "@Url.Action("CountReport", "Home")?start=" + start + "&end=" + end;
                    });

                SetTime();

            });

        function ShowList(mmsi,type) {
            var start = GetQueryString("start");
            var end = GetQueryString("end");
            if (start == null) 
            {
                start="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))";
            }
                if (end == null) 
            {
                end="@(DateTime.Now.ToString("yyyy-MM-dd"))";
            }

            window.open("@Url.Action("ReportList","Home")?start=" + start + "&end=" + end + "&mmsi=" + mmsi + "&type=" + type);
        }

        function SetTime() {
            var start = GetQueryString("start");
            var end = GetQueryString("end");
            if (start != null) {
                $("#start").val(start);
            }else
            {
                $("#start").val("@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))");

            }
            if (end != null) {
                $("#end").val(end);
            }else
            {
                $("#end").val("@(DateTime.Now.ToString("yyyy-MM-dd"))");

            }
        }
    </script>
}
